from ...service.security_module import SecurityModule, FunctionName, PermissionName
from ...service.buss_iec.competence_assessment import CompetenceAssessmentService
'''
@Author: your name
@Date: 2019-09-25 09:48:29
@LastEditTime: 2019-12-05 13:46:32
@LastEditors: your name
@Description: In User Settings Edit
@FilePath: \IntelligentElderlyCare\server\register\buss_iec\competence_assessment_register.py
'''
# -*- coding: utf-8 -*-
'''
能力评估服务注册
'''


def register(jsonrpc, db_addr, db_port, db_name, db_user, db_pwd, inital_password, session):
    competence_assessment_func = CompetenceAssessmentService(
        db_addr, db_port, db_name, db_user, db_pwd, inital_password, session)
    security_service = SecurityModule(
        db_addr, db_port, db_name, db_user, db_pwd, inital_password, session)

    @jsonrpc.method('ICompetenceAssessmentService.get_competence_assessment_list_all')
    def __get_nursing_list_all(condition, page, count):
        permission_data = security_service.judge_permission_query(
            FunctionName.competenct_assessment_all, PermissionName.query)
        res = competence_assessment_func.get_competence_assessment_list(permission_data,
                                                                        condition, page, count)
        return res

    @jsonrpc.method('ICompetenceAssessmentService.get_competence_assessment_list_look')
    def __get_nursing_list_look(condition, page, count):
        permission_data = security_service.judge_permission_query(
            FunctionName.competenct_assessment_look, PermissionName.query)
        res = competence_assessment_func.get_competence_assessment_list(permission_data,
                                                                        condition, page, count)
        return res

    @jsonrpc.method('ICompetenceAssessmentService.get_competence_assessment_list')
    def __get_nursing_list_look(condition, page, count):
        permission_data = security_service.org_all_subordinate()
        res = competence_assessment_func.get_competence_assessment_list(permission_data,
                                                                        condition, page, count)
        return res

    @jsonrpc.method('ICompetenceAssessmentService.update_competence_assessment')
    def __update_user(competence_assessment):
        if 'id' in list(competence_assessment.keys()):
            __p = security_service.judge_permission_other(
                FunctionName.competenct_assessment_all, PermissionName.edit)
        else:
            __p = security_service.judge_permission_other(
                FunctionName.competenct_assessment_all, PermissionName.add)
        res = competence_assessment_func.update_competence_assessment(
            competence_assessment)
        return res

    @jsonrpc.method('ICompetenceAssessmentService.delete_competence_assessment')
    def __delete_user(competence_assessment_ids):
        __p = security_service.judge_permission_other(
            FunctionName.competenct_assessment_all, PermissionName.delete)
        res = competence_assessment_func.delete_competence_assessment(
            competence_assessment_ids)
        return res
